package com.ruoyi.mp.controller;

import com.ruoyi.common.core.utils.QRCodeUtils;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.db.domain.system.MpClient;
import com.ruoyi.db.domain.system.MpTeamApply;
import com.ruoyi.db.domain.system.PcTeamConfig;
import com.ruoyi.mp.annotion.Login;
import com.ruoyi.mp.annotion.LoginUser;
import com.ruoyi.mp.service.IMpTeamApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【店铺申请表】Controller
 * 
 * @author ruoyi
 * @date 2022-07-23
 */
@Api(value = "【店铺申请表】",tags ="【店铺申请表】")
@RestController
@RequestMapping("/smp/team/apply")
public class MpTeamApplyController extends BaseController
{
    private static Logger log = LoggerFactory.getLogger(MpTeamApplyController.class);
    @Autowired
    private IMpTeamApplyService mpTeamApplyService;

    /**
     * 查询【店铺申请表】列表
     */
    @Login
    @ApiOperation(value = "查询【店铺申请表】列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="mpTeamApply",value="【店铺申请表】",paramType="form")
    })
    @GetMapping("/list")
    public TableDataInfo list(String isOperCenter,@LoginUser MpClient client)
    {
        try {
            MpTeamApply mpTeamApply = new MpTeamApply();
            mpTeamApply.setClientId(client.getClientId());
            mpTeamApply.setIsOperCenter(isOperCenter);
            startPage();
            List<MpTeamApply> list = mpTeamApplyService.selectMpTeamApplyList(mpTeamApply,client);
            return getDataTable(list);
        }catch (Exception e){
            log.error("【店铺申请表】发生异常",e);
        }
        return null;
    }


    /**
     * 获取【店铺申请表】详细信息
     */
    @ApiOperation(value = "获取【店铺申请表】详细信息")
    @ApiImplicitParam(name="teamApplyId",value="【店铺申请表】")
    @GetMapping(value = "/{teamApplyId}")
    public AjaxResult getInfo(@PathVariable("teamApplyId") Long teamApplyId)
    {
        try {
            return AjaxResult.success(mpTeamApplyService.selectMpTeamApplyByTeamApplyId(teamApplyId));
        }catch (Exception e){
            log.error("【店铺申请表】发生异常",e);
        }
        return AjaxResult.error("【店铺申请表】异常");
    }

    /**
     * 新增【店铺申请表】
     */
    @Login
    @ApiOperation(value = "新增【店铺申请表】")
    @ApiImplicitParams({
            @ApiImplicitParam(name="mpTeamApply",value="【店铺申请表】",dataType="MpTeamApply")
    })
    @Log(title = "【店铺申请表】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MpTeamApply mpTeamApply, @LoginUser MpClient client)
    {
        try {
            mpTeamApply.setClientId(client.getClientId());
            mpTeamApplyService.insertMpTeamApply(mpTeamApply);
            return AjaxResult.success("申请成功");
        }catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }
    }

    @ApiOperation(value = "查询团队配置表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="teamConfig",value="查询团队配置表",paramType="form")
    })
    @GetMapping("/team/list")
    public AjaxResult teamList(PcTeamConfig teamConfig)
    {
        try {
            List<PcTeamConfig> list = mpTeamApplyService.selectMpTeamList(teamConfig);
            return AjaxResult.success(list);
        }catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }
    }


}
